package org.example.common.support;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.common.configs.exception.ErrorEnum;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class APIResponse<T> implements Serializable {

    private static final long serialVersionUID = -3983224420475260311L;
    private String code;
    private String msg;
    private T data;

    public static <T> APIResponse<T> ok() {
        return ok(null);
    }

    public static <T> APIResponse<T> ok(T t) {
        return new APIResponse<>(ErrorEnum.e_0000.getCode(), ErrorEnum.e_0000.getMsg(), t);
    }

    public static <T> APIResponse<T> fail(String code, String msg) {
        return new APIResponse<>(code, msg, null);
    }

    public static <T> APIResponse<T> fail(ErrorEnum error) {
        return new APIResponse<>(error.getCode(), error.getMsg(), null);
    }

}
